#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFile>
#include <QDebug>
#include <QIODevice>
#include <QMediaDevices>
#include <QAudioFormat>
#include <QAudioSink>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

/**
 * \brief 播放的输入数据必须从QIODevice设备中送往QAudioSink
 */
class PcmInputDevice : public QIODevice
{
    Q_OBJECT

public:
    PcmInputDevice();
    ~PcmInputDevice();
    void start();
    void stop();
    qint64 readData(char *data, qint64 maxlen) override;
    qint64 writeData(const char *data, qint64 len) override;

private:
    QFile m_inputFile;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    QAudioSink *m_audioSinkOutput;
    QMediaDevices *m_outputDevices;
    QAudioDevice m_outputDevice;
    PcmInputDevice *m_pcmInputDevice;
};
#endif // MAINWINDOW_H
